#!/bin/bash
function install_memcached() {
echo -e "${blue}当前正在执行的操作为:${nocolor} ${green}安装Memcached${nocolor}\n"

mcacheSize=
while [[ ! $mcacheSize =~ ^[1-9][0-9]*$ ]]
do
    echo -ne "设置memcached缓存大小，返回请输入N，请输入: "
    read mcacheSize
    if [[ $mcacheSize == [Nn] ]];then
        return 1
    fi
    if [[ ! $mcacheSize =~ ^[1-9][0-9]*$ ]];then
        echo -e "$Error 缓存大小必须大于零的数字, 请重新输入!"
        sleep 0.15
    fi
done
echo ""
echo -e "${cyan}开始执行memcached安装${nocolor}"
sleep 0.15

echo -e "$Info ${purple}开始安装Memcached${nocolor}"
if [ "$die_network" == "true" ];then
   rpm -ivh $workHome/packages/memcached/el$system_ver/*.rpm
else
   yum install -y memcached
fi
if [ "$?" == "0" ];then 
    echo -e "$Info ${purple}设置memcached缓存大小${nocolor}"
    sed -i "s/CACHESIZE.*/CACHESIZE=\"$mcacheSize\"/" /etc/sysconfig/memcached
 
    echo -e "$Info ${purple}启动memcached${nocolor}"
    service memcached restart
    
    sleep 0.30
fi
#判断是否启动
memPid=`pidof memcached`
if [ -n "$memPid" ];then
   echo -e "$Info ${light_green}memcached安装成功${nocolor}"
else
   echo -e "$Error memcached安装失败"
fi

echo ""
echo -ne "${cyan}$msg, 按任意键返回!${nocolor}"
read -s -n1 goback
echo -e ""
}